package com.mycomp.cm.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;

@Entity
@Table(name = "CM_CONTACTS", schema = "chpc")

public class Contact implements Serializable, Comparable<Contact> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int contSNo;
	@NotEmpty(message = "Name is Required")
	private String contName;
	@NotEmpty(message = "Email is Required")
	@Email(message = "Invalid Email")
	private String contEmail;
	@Column(length = 11)
	@Pattern(regexp = "\\d{10}", message = "Invalid Mobile")
	private String contMobile;
	@Temporal(TemporalType.DATE)
	private Date contDOB;
	private String contAddress;

	@Transient
	private String contType;

	@ManyToOne
	@JoinTable(name = "USER_CONTACTS", joinColumns = { @JoinColumn(name = "CONTACT_ID") }, inverseJoinColumns = { @JoinColumn(name = "USERNAME") })
	private User contactUser;

	public int getContSNo() {
		return contSNo;
	}

	public void setContSNo(int contSNo) {
		this.contSNo = contSNo;
	}

	public String getContName() {
		return contName;
	}

	public void setContName(String contName) {
		this.contName = contName;
	}

	public String getContEmail() {
		return contEmail;
	}

	public void setContEmail(String contEmail) {
		this.contEmail = contEmail;
	}

	public String getContMobile() {
		return contMobile;
	}

	public void setContMobile(String contMobile) {
		this.contMobile = contMobile;
	}

	public String getContAddress() {
		return contAddress;
	}

	public void setContAddress(String contAddress) {
		this.contAddress = contAddress;
	}

	public Date getContDOB() {
		return contDOB;
	}

	public void setContDOB(Date contDOB) {
		this.contDOB = contDOB;
	}

	public String getContType() {
		return contType;
	}

	public void setContType(String contType) {
		this.contType = contType;
	}

	
	public int compareTo(Contact o) {
		return this.getContName().compareTo(o.getContName());
	}

	public User getContactUser() {
		return contactUser;
	}

	public void setContactUser(User contactUser) {
		this.contactUser = contactUser;
	}

}
